home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / ICVT.ICN < prev    next >
Text File  |  1992-11-26  |  2KB  |  94 lines

  1. ############################################################################
  2. #
  3. #    File:     icvt.icn
  4. #
  5. #    Subject:  Program for ASCII/EBCDIC program conversion
  6. #
  7. #    Author:   Cheyenne Wills, modified by Ralph E. Griswold
  8. #
  9. #    Date:     September 7, 1990
  10. #
  11. ###########################################################################
  12. #
  13. #  This program converts Icon programs from ASCII syntax to EBCDIC syntax
  14. #  or vice versa. The option -a converts to ASCII, while the option
  15. #  -e converts to EBCDIC. The program given in standard input is written
  16. #  in coverted form to standard output.
  17. #
  18. ############################################################################
  19.  
  20. global outf,process,bb,quotechar
  21. global nrbrack,nlbrack,nrbrace,nlbrace,rbrack,lbrack,rbrace,lbrace
  22.  
  23. procedure main(args)
  24.    local line
  25.  
  26.    case map(args[1]) | stop("Usage: icvt -a | -e") of {
  27.        "-a" : {
  28.        lbrace := "$("; nlbrace := "{"
  29.        rbrace := "$)"; nrbrace := "}"
  30.        lbrack := "$<"; nlbrack := "["
  31.        rbrack := "$>"; nrbrack := "]"
  32.        bb := '$'
  33.        }
  34.        "-e" : {
  35.        lbrace := "{"; nlbrace := "$(";
  36.        rbrace := "}"; nrbrace := "$)";
  37.        lbrack := "["; nlbrack := "$<";
  38.        rbrack := "]"; nrbrack := "$>";
  39.        bb := '[]{}'
  40.        }
  41.        default :
  42.        stop("Usage: icvt -a | -e")
  43.        }
  44.  
  45.    process := standard
  46.  
  47.    while line := read() do {
  48.        line ||:= "\n"
  49.        line ? while not pos(0) do
  50.        process()
  51.        }
  52.  
  53. end
  54.  
  55. procedure standard()
  56.    writes(tab(upto( '"\'#' ++ bb))) | (writes(tab(0)) & return)
  57.  
  58.    if match("#") then {
  59.        writes(tab(0))
  60.        }
  61.    else if any('\'"') then {
  62.        process := inquote
  63.        quotechar := move(1)
  64.        writes(quotechar)
  65.        }
  66.    else if match(lbrack) then {
  67.        move(*lbrack)
  68.        writes(nlbrack)
  69.        }
  70.    else if match(rbrack) then {
  71.        move(*rbrack)
  72.        writes(nrbrack)
  73.        }
  74.    else if match(lbrace) then {
  75.        move(*lbrace)
  76.        writes(nlbrace)
  77.        }
  78.    else if match(rbrace) then {
  79.        move(*rbrace)
  80.        writes(nrbrace)
  81.        }
  82.    else writes(move(1))
  83.    return
  84. end
  85.  
  86. procedure inquote()
  87.    writes( tab(upto( quotechar ++ '\\')) ) |
  88.        (writes(tab(0)) & return)
  89.    writes(="\\") & writes(move(1)) & return
  90.    writes( =quotechar )
  91.    process := standard
  92.    return
  93. end
  94.